package com.b2b.config;

import com.b2b.util.JedisUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

//指定为切面类
@Aspect
//将该类放入Spring容器中
@Component
public class Interceptor {



    //拦截所有Controller
    @Pointcut("execution(public * com.b2b..*Controller.*(..))")
    public void totalController(){}


    //在这个方法执行后
    @After("totalController()")
    public void totalVisit() throws Throwable {
//        Object[] objs=joinPoint.getArgs();
//        Long id=(Long) objs[0];
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String today = format.format(new Date());
        JedisUtil.incInt(today, 1, (long) 1300000);
    }
}